package cn.com.tarotframework.config.api;


import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

/**
 * copyright (C), 2022, 塔罗牌基础架构
 *
 * @author xincan
 * @version 0.0.1-SNAPSHOT
 * @program tarot-openapi-spring-boot-starter
 * @date 2023/1/13 09:30
 * @description 自定义条件查询注解，解决openapi文档bean是否是加载
 */
public class TarotConditionalOnAutoGroupApi implements Condition {

    private static final String TAROT_OPENAPI_GROUP = "tarot.openapi.group.group-configs[1].group";

    /**
     * 判断配置文件中是否有分组数据且分组总数大于2
     * @param context 条件注解范围内的上下文对象
     * @param metadata 条件注解可获取的元数据对象
     * @author xincan
     * @date 2023/1/13 16:01
     * @return boolean
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        return StringUtils.hasText(
                context.getEnvironment().getProperty("tarot.openapi.group.group-configs[1].group")
        );
    }

}
